clear; clc; close all

models = {'Exponential','Weibull','Loglogistic','Lognormal'};
types = {'LD','HD'};
losses = {'L1','L2'};

for model = models,
    for type = types,
        for loss = losses,
            dir = 'C:\Users\Mittal\Documents\Work\Code\survival-analysis-cmake\pparametric\release\';
            nFiles = 5;
            base = 'mod_file';
            
            beta = [];
            for i = 0:nFiles-1,
                fname = [dir model{1} '_' base '_' type{1} '_' loss{1} '_' num2str(i)];
                d = dlmread(fname);
                if(i == 0)
                    beta = d(:,2);
                else
                    beta = beta + d(:,2);
                end
            end
            beta = beta/nFiles;
            
            outname = [dir model{1} '_' base '_' type{1} '_' loss{1} '_avg'];
            d(:,2) = beta;
            
            format short g
            
            dlmwrite(outname,d,'precision',100);
        end
    end
end